
/*
 * @Author: c
 * @Date: 2023-12-26 12:14:46
 * @LastEditTime: 2024-01-17 04:42:52
 * @LastEditors: c
 * @Description: 
 * @FilePath: \music-web-backend\src\core\system\dict\dict.controller.ts
 * https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { Body, Controller, Delete, Get, Param, ParseIntPipe, Post, Put, Query } from '@nestjs/common';
import { DictService } from './dict.service';
import { DictForm } from './dto/create-dict.dto';
import { DictPageQuery } from './dto/search-dict.dto';

@Controller('dict')
export class DictController {
  constructor(private readonly dictService: DictService) { }


  /**
   * 字典下拉列表
   * @param typeCode 
   * @returns 
   */
  @Get(":typeCode/options")
  listDictOptions(
    @Param('typeCode') typeCode
  ) {
    return this.dictService.listDictOptions(typeCode);

  }
  //字典-所有类型-分页列表
  @Get("page")
  public getDictPage(
    @Query() queryParams: DictPageQuery
  ) {
    return this.dictService.getDictPage(queryParams);

  }

  /**
 * 字典-新增
 * @param createDictDto 
 * @returns 
 */
  @Post()
  create(@Body() createDictDto: DictForm) {
    return this.dictService.create(createDictDto);
  }


  /**
   * 字典-查询单条数据
   * @param id 
   * @returns 
   */
  @Get(':id/form')
  findOne(@Param('id', ParseIntPipe) id: number) {
    return this.dictService.findOne(id);
  }




  /**
   * 字典-修改单条数据
   * @param id 
   * @param updateDictTypeDto 
   * @returns 
   */
  @Put(':id')
  update(@Param('id', ParseIntPipe) id: number, @Body() updateDictTypeDto: DictForm) {
    return this.dictService.update(id, updateDictTypeDto);
  }

  /**
   * 字典-根据ID删除数据
   * @param id 
   * @returns 
   */
  @Delete(':ids')
  remove(@Param('ids') ids: string) {
    return this.dictService.removeByIds(ids);
  }
}
